package com.smforj.ssm.mina.client;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;

/** 
 * 客户端业务处理逻辑 
 *  
 * @author ghj
 */  
public class MinaClientHandlerAdapter extends IoHandlerAdapter {  
	private static int iCount = 1;
    // 当客户端连接进入时  
    @Override  
    public void sessionOpened(IoSession session) throws Exception {  
        System.out.println("MinaClientHandlerAdapter incomming 客户端: "+(iCount++)+"  " + session.getRemoteAddress());  
        //session.write("i am coming");  
    }  
  
    @Override  
    public void exceptionCaught(IoSession session, Throwable cause)  
            throws Exception {  
        System.out.println("MinaClientHandlerAdapter 客户端发送信息异常...."+(iCount++)+"  "+cause.getMessage());  
    }  
  
    // 当客户端发送消息到达时  
    @Override  
    public void messageReceived(IoSession session, Object message)  
            throws Exception {   
        System.out.println("MinaClientHandlerAdapter 服务器返回的数据：" +(iCount++)+"  "+ message.toString());  
    }  
    
    @Override
    public void messageSent(IoSession session, Object message) throws Exception { 
    	System.out.println("MinaClientHandlerAdapter messageSent："+(iCount++)+"  " + message.toString()); 
    	super.messageSent(session, message);
    	//session.write(message);
    };
  
    @Override  
    public void sessionClosed(IoSession session) throws Exception {  
        System.out.println("MinaClientHandlerAdapter 客户端与服务端断开连接....."+(iCount++)+"  ");  
    }  
  
    @Override  
    public void sessionCreated(IoSession session) throws Exception {  
        System.out.println("MinaClientHandlerAdapter one Client Connection " +(iCount++)+"  "+ session.getRemoteAddress());  
        //session.write("我来了······");  
    }  
  
}  
